package com.example.mapper;
//由于启动类扫描了 @MapperScan("com.example.mapper")，所以 EmpMapper 接口不需要添加 @Mapper 注解

import com.example.entity.dto.EmpDto;
import com.example.entity.dto.EmpLoginDto;
import com.example.entity.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

public interface EmpMapper {


    @Delete("delete from emp where id = #{id}")
    public int deleteEmpById(Integer id);

    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    @Insert("insert into emp(username,password,name,gender,image,job,entryDate,dept_id,create_time,update_time) values(#{username},#{password},#{name},#{gender},#{image},#{job},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    public int insertEmp(Emp emp);

    @Update("update emp set username = #{username},name = #{name},update_time = #{updateTime} where id = #{id}")
    public int updateEmpById(Emp emp);

    @Select("select * from emp where id = #{id}")
    public Emp getById(Integer id);

    //条件查询
    @Select("select * from emp where username like concat('%',#{username},'%') and gender=#{gender} and entrydate between #{start} and #{end}")
    public List<Emp> getByCondition(@Param("username") String username,@Param("gender") Byte gender,@Param("start") LocalDate start,@Param("end") LocalDate end);

//    @Select("select * from emp limit #{start},#{pageSize}")
//    public List<Emp> getByPage(@Param("start") Integer start, @Param("pageSize") Integer pageSize);
    /*@Select("select count(*) from emp")
    public Long getTotal();*/
    //分页插件自动添加limit，且自动计算总数量
    @Select("select * from emp")
    public List<Emp> getByPage();
    List<Emp> getByPage2(EmpDto empDto);


    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp getByNameAndPwd(EmpLoginDto empLoginDto);

    @Delete("delete from emp where dept_id=#{id}")
    int deleteByDeptId(Integer id);
}
